<?

require_once SITE_ROOT_PATH."/_lib/classes/class.hotels.php";

class hotel_special_offers {



// FUNCTION // get all the special offers added to the system
function get_specials($params=''){
	
	// use safe function
	$params = in($params);

	if($params['limit']) $sql_limit = " LIMIT ".$params['limit']." ";
	if($params['order']=='random'){
		$sql_order = " ORDER BY RAND() ";
	}else{
		$sql_order = " ORDER BY special_offer_id DESC ";
	}
	
	$sql = "SELECT * 
	FROM hotel_special_offers
	WHERE 1 = 1 
	".$sql_where."
	".$sql_order."
	".$sql_limit."";

	$result = mysql_query($sql) or die (mysql_error());
	$num_rows = mysql_num_rows($result);

	if($num_rows){
		$values_array = array();
		while($row = mysql_fetch_array($result, MYSQL_BOTH)) {
			$values_array[] = array_map('array_stripslashes', $row);
			
		}
		return $values_array;
	}else{
		return false;
	}
	

}



// FUNCTION // holiday results based on special_offer_id
function get_special($params=''){

if(!empty($params['special_offer_id'])){


	$sql = "SELECT * FROM hotel_special_offers
	WHERE special_offer_id = ".$params['special_offer_id']."
	LIMIT 1"; 
	
	$result = mysql_query($sql) or die (mysql_error());
	$num_rows = mysql_num_rows($result);

	if($num_rows){
		$row = mysql_fetch_array($result, MYSQL_BOTH);
		$row = array_map('array_stripslashes', $row);
		return $row;
	}else{
		return false;
	}

}

}







// FUNCTION // Validate form
function validate_form($results){

	// error variable
	$errors = array();
	
	// get hotel details
	$hotels = new hotels();
	$params['tree_id'] = $results['hotel_tree_id'];
	$hotel_values = $hotels->get_hotel($params);

	if(empty($hotel_values)) array_push($errors, 'Hotel not found');
	if(empty($results['price_per_night'])) array_push($errors, 'Please enter the price per night');

	return $errors;
	
}


// FUNCTION // delete special offer
function delete_special_offer($params){

	if(!empty($params['special_offer_id'])){
	
		$sql = "DELETE FROM hotel_special_offers
		WHERE special_offer_id = '".$params['special_offer_id']."'";
		
		$result = mysql_query($sql) or die (mysql_error());

	}

}



// FUNCTION // insert offer details
function insert_offer($params){

if(!empty($params)){

	// use safe function
	$params = in($params);
	
	$sql = "INSERT INTO hotel_special_offers
	SET	hotel_tree_id = '".$params['hotel_tree_id']."',
	price_per_night = '".$params['price_per_night']."', 
	#date_expiry = '".$params['date_expiry']."',
	date_added = '".mktime()."' "; 
	
	$result = mysql_query($sql) or die (mysql_error());
	
}
	
}






// FUNCTION // Update the offer details
function update_offer($params){

if(!empty($params)){

	// use safe function
	$params = in($params);
	
	$sql = "UPDATE hotel_special_offers
	SET	hotel_tree_id = '".$params['hotel_tree_id']."',
	price_per_night = '".$params['price_per_night']."',
	date_expiry = '".$params['date_expiry']."',
	date_added = '".mktime()."' 
	WHERE special_offer_id = '".$params['special_offer_id']."' "; 
	
	$result = mysql_query($sql) or die (mysql_error());

}


}



}

?>